using System.Collections.Generic;
using UnityEngine;

namespace Game.Terrain.Terrain
{
    public class GameGridBase
    {
        Grid _grid;
        Transform Parent;
        GridLayout.CellLayout _cellLayout;

        public GameGridBase(Transform parent, int length, int width, int height,GridLayout.CellLayout cellLayout= GridLayout.CellLayout.Rectangle)
        {
            Parent = parent;
            Length = length;
            Width = width;
            Height = height;
            _cellLayout = cellLayout;
        }
        private HashSet<int> _emptyPositions = new HashSet<int>(); // 使用 int 值存储空位置

        public float Height { get; set; }

        public float Width { get; set; }

        public float Length { get; set; }

        public void Init()
        {
            _grid = new GameObject($"TerrainGrid{Length}x{Width}x{Height}").AddComponent<Grid>();
            _grid.transform.SetParent(Parent);
            _grid.cellSize = new Vector3(Length, Width, Height);
            _grid.cellLayout = _cellLayout;
        }

        public Vector3 GetCellCenterWorld(Vector3Int position)
        {
            return _grid.GetCellCenterWorld(position);
        }

        public Vector3Int WorldToCell(Vector3 position)
        {
            return _grid.WorldToCell(position);
        }

        public Vector3Int LocalToCell(Vector3 position)
        {
            return _grid.LocalToCell(position);
        }

        public Vector3 CellToLocal(Vector3Int position)
        {
            return _grid.CellToLocal(position);
        }

        public Vector3 CellToWorld(Vector3Int position)
        {
            return _grid.CellToWorld(position);
        }

        public Bounds GetBoundsLocal(Vector3Int position)
        {
            return _grid.GetBoundsLocal(position);
        }

        public Vector3 CellToLocalInterpolated(Vector3 position)
        {
            return _grid.CellToLocalInterpolated(position);
        }

        public Vector3 GetLayoutCellCenter()

        {
            return _grid.GetLayoutCellCenter();
        }
        
    }
}